package com.cl.mypureframe.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.Target;
import com.cl.photozoom.ui.PhotoActivity;

import java.util.concurrent.ExecutionException;

/**
 * @Class: PhotoZoomGlideEngine
 * @Description:
 * @Author: ChenLei
 * @Date: 2020/12/23---14:48
 */
public class PhotoZoomGlideEngine implements com.cl.photozoom.ui.ImageEngine {
    private static PhotoZoomGlideEngine instance;

    private PhotoZoomGlideEngine() {
    }

    public static PhotoZoomGlideEngine createGlideEngine() {
        if (null == instance) {
            synchronized (PhotoZoomGlideEngine.class) {
                if (null == instance) {
                    instance = new PhotoZoomGlideEngine();
                }
            }
        }
        return instance;
    }

    @Override
    public void loadImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
        ImageUtils.glideLoader(context, url, imageView);
    }

    @Override
    public Bitmap downloadBitmap(@NonNull Context context, @NonNull String url) throws ExecutionException, InterruptedException {
        return Glide.with(context)
                .asBitmap()
                .load(url)
                .submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                .get();

    }
}
